package com.sys.servlet.mgr.course;

import com.sys.pojo.JsonResult;
import com.sys.service.CourseService;
import com.sys.service.CustomerService;
import com.sys.utils.WriteJson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/mgr/course/modifyById")
public class ModifyByIdServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        PrintWriter writer = resp.getWriter();
        String cname = req.getParameter("cname");
        String ctime = req.getParameter("ctime");
        String cplace = req.getParameter("cplace");
        String tid = req.getParameter("tid");
        String stat = req.getParameter("stat");
        String produce = req.getParameter("produce");
        String cid = req.getParameter("cid");
        Integer cidInt = Integer.parseInt(cid);
        JsonResult jr = new JsonResult();

        CourseService courseService = new CourseService();
        try {
            //问题：如何获取当前登录用户的id
            courseService.update(cname,ctime,cplace,tid,stat,produce,cidInt);
            // 一般情况，一个servlet跳转到另一个servlet用的是重定向
            jr.setCode(0);
            jr.setMsg("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            jr.setCode(500);
            jr.setMsg("操作发生错误");
        }
        WriteJson.write(resp,jr);

    }
}
